#include "FpTxtWriter.h"

#include <iostream>
#include <fstream>
#include <ctime>
#include <iomanip>
#include <sstream>



FP_FILE_BEGIN

//FpTxtWriter::FpTxtWriter()
//{
//
//}
//
//FpTxtWriter::~FpTxtWriter()
//{
//
//}

bool FpTxtWriter::WriteDoubleToTxt(const std::string& txt, const std::string& dataName, double data, int prec = 2)
{
	std::ofstream file(txt, std::ios::app);
	if (file.is_open()) {
		auto now = std::time(nullptr);
		auto localTime = *std::localtime(&now);

		std::ostringstream oss;
		oss << std::put_time(&localTime, "%Y-%m-%d %H:%M:%S");
		std::string timestamp = oss.str();
		file << "< " << timestamp << " > ------ " <<dataName << " : " << std::fixed << std::setprecision(prec) << data << std::endl;
		file.close();
		return true;
	}
	else {
		return false;
	}
}

bool FpTxtWriter::qWriteDoubleToTxt(const std::string& txt, const std::string& dataName, double data, int prec /*= 2*/)
{

}

FP_FILE_END